package com.example.springbootmybatis.controller;



import com.example.springbootmybatis.dao.UserDao;
import com.example.springbootmybatis.entity.AliPay;
import com.example.springbootmybatis.entity.User;
import com.example.springbootmybatis.service.ImplUserService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
public class Hellocontroller {
   // @GetMapping("/hello")
   // public Map<String,Object> hello(){
   //     Map<String,Object> map = new HashMap<>();
   //     map.put("name","赵");
   //     map.put("age",18);
   //     return map;
   // }
//
   // @Autowired
   // private AliPay aliPay;
   // @GetMapping("/index")
   // public AliPay index(){
   //     return aliPay;
  // }

   // @Value("${server.port}")
  //  private Integer port;




   // @Autowired
   // private ImplUserService userService;
   // @GetMapping("/all")
   // @ApiOperation(value = "获取所有用户信息")
   // @ApiImplicitParams({
   //         @ApiImplicitParam(name = "current", value = "当前页码",required = true),
   //         @ApiImplicitParam(name = "pageSize", value = "显示个数",required = true)
   // })
   // public PageInfo<User> list(Integer current , Integer pageSize){
//
   //     return userService.findBypage(current,pageSize);
   // }
//
   // @PostMapping("/insert")
   // @ApiOperation(value = "添加用户")
   // @ApiImplicitParams({
   //         @ApiImplicitParam(name = "s_name", value = "姓名",required = true),
   //         @ApiImplicitParam(name = "age", value = "年龄",required = true),
   //         @ApiImplicitParam(name = "email", value = "邮箱",required = true)
   // })
   // public int insert(String s_name,String age,String email){
   //     return userService.insert(s_name, age, email);
   // }
//
   // @PutMapping("/update")
   // @ApiOperation(value = "根据id修改数据")
   // @ApiImplicitParams({
   //         @ApiImplicitParam(name = "s_name", value = "姓名",required = true),
   //         @ApiImplicitParam(name = "age", value = "年龄",required = true),
   //         @ApiImplicitParam(name = "email", value = "邮箱",required = true),
   //         @ApiImplicitParam(name = "id", value = "编号",required = true)
   // })
   // public int update(String s_name, String age ,String email, int id) {
   //     return userService.update(s_name, age, email, id);
   // }
//
   // @DeleteMapping("/delete")
   // @ApiOperation(value = "根据id删除数据")
   // @ApiImplicitParam(name = "id", value = "编号",required = true)
   // public int delete(int id){
   //     return userService.delete(id);
   // }
   @Autowired
   private UserDao userDao;

    @GetMapping("all")
    public PageInfo<User> list(Integer current, Integer pageSize) {
        List<User> all = userDao.selectList(null);
        PageInfo<User> pageInfo = new PageInfo<>(all);
        return pageInfo;
    }

    @GetMapping("insert")
    public int insert(User user) {
        int row = userDao.insert(user);
        return row;
    }

    @GetMapping("update")
    public int update(User user) {
        int row = userDao.updateById(user);
        return row;
    }

    @GetMapping("delete")
    public int delete(Integer uid) {
        int row = userDao.deleteById(uid);
        return row;
    }

}
